import os.path
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
url = 'file:///' + os.path.abspath('html') + '/popup.html'
driver.get(url)

# alter
time.sleep(2)
btn_list = driver.find_element(By.TAG_NAME,'button') # 返回列表，webelement 的3个对象
btn_list[0].click()

# TODO 切换到弹窗
time.sleep(2)
alter = driver.switch_to.alert
alter.accept()    # 确定

# todo confirm
btn_list[1].click()
# todo 切换到弹窗
alter = driver.switch_to.alert
time.sleep(2)

# 确定
#alter.accept()

# 获取弹窗的的文本
print(alter.text)
# 取消
alter.dismiss()

# todo  prompt 输入框弹框
time.sleep(2)
btn_list[2].click()

# 切换到弹窗
alter = driver.switch_to.alert
# 输入内容
time.sleep(2)
alter.send_keys('ok')
# 获取弹窗文本
print(alter.text)

# 确定
time.sleep(2)
alter.accept()

# 取消
#alter.dismiss()

#退出浏览器
time.sleep()
driver.quit()

